package com.gxa.p2p.service.impl;

import com.gxa.p2p.mapper.CertificateMaterialMapper;
import com.gxa.p2p.pojo.CertificateMaterial;
import com.gxa.p2p.service.CertificateMaterialService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @description
 * @date 2020.8.1
 */
@Service("certificateMaterialService")
@Transactional(readOnly = true, propagation = Propagation.SUPPORTS, isolation = Isolation.DEFAULT)
public class CertificateMaterialServiceImpl implements CertificateMaterialService {

    @Resource
    CertificateMaterialMapper certificateMaterialMapper;

    @Override
    public CertificateMaterial selectById(Integer id) {
        return certificateMaterialMapper.selectByPrimaryKey(id);
    }

    /**
     * 带条件,且条件含有非空判断的全查询
     * @param map
     * @return List
     */
    @Override
    public List<CertificateMaterial> findAll(Map<String,Object> map) {
        int page = ((Integer) map.get("page") - 1) * (Integer) map.get("limit");
        map.put("page",page);
        return certificateMaterialMapper.findAll(map);
    }

    /**
     * 计算带条件的数据总数
     * @param map
     * @return Integer
     */
    @Override
    public Integer dataSum(Map<String,Object> map) {
        return certificateMaterialMapper.dataSum(map);
    }

    /**
     * 添加(改)审核信息
     * @param certificateMaterial
     * @return Integer
     */
    @Override
    @Transactional(readOnly = false, propagation = Propagation.REQUIRED, isolation = Isolation.READ_COMMITTED, rollbackFor = {Throwable.class})
    public Integer updateReviewStatus(CertificateMaterial certificateMaterial) {
        return certificateMaterialMapper.updateReviewStatus(certificateMaterial);
    }

    @Override
    public boolean saveCer(CertificateMaterial certificateMaterial) {
        return certificateMaterialMapper.insertSelective(certificateMaterial) > 0;
    }

    /**
     * 风控审核查询
     * @param userId
     * @return
     */
    @Override
    public CertificateMaterial findByCM(Integer userId) {
        return certificateMaterialMapper.findByCM(userId);
    }
}
